package AddProduct;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ChooseSizeAndColor
 * This servlet gives option to customer to choose material and category of new product.
 * @author desso
 */
@WebServlet("/ChooseSizeAndColor")
public class ChooseSizeAndColor extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ChooseSizeAndColor() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {				 
		    Connection databaseConnection = SQL.getConnection();
			ResultSet  resultSetForColor = SQL.getDataFromDatabase(databaseConnection, SQLStatements.STATMENT_FOR_COLORS);
			ResultSet  resultSetForSize = SQL.getDataFromDatabase(databaseConnection, SQLStatements.STATMENT_FOR_SIZES);
			response.setCharacterEncoding("UTF-8");
			PrintWriter prinWriter = response.getWriter();
			response.setContentType("text/html");
			
			prinWriter.println("<!DOCTYPE html>");
			prinWriter.println("<html>");
			prinWriter.println("   <head>");
			prinWriter.println("   </head>");
			prinWriter.println("    <body>");
			prinWriter.println("      <h3> Please choose color and size of the new product! </h3>");		
			prinWriter.println("      <form name=\"new product\" action=\"InsertIntoClothingInventory\" method=\"post\">");			
			HTML.printSelect(prinWriter, resultSetForColor, "color");			
			HTML.printSelect(prinWriter, resultSetForSize, "size");
			prinWriter.println("           count: <input type=\"number\" name=\"count\"> ");						
			prinWriter.println("         <input type=\"submit\" value=\"Continue\">");	
			prinWriter.println("       </form> ");
			prinWriter.println("    </body>");
			prinWriter.println("</html>");

		} catch (SQLException | ClassNotFoundException e) {
			e.printStackTrace();
		}		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
